<template>
  <div class="home">
    <h1>测试上传</h1>
    <el-upload ref="uploadRef" class="upload-demo" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
      :auto-upload="false">
      <template #trigger>
        <el-button type="primary">select file</el-button>
      </template>

      <el-button class="ml-3" type="success" @click="submitUpload">
        upload to server
      </el-button>

      <template #tip>
        <div class="el-upload__tip">
          jpg/png files with a size less than 500kb
        </div>
      </template>
    </el-upload>
    <div>
      <el-button type="" @click="mockClick">测试mock</el-button>
    </div>
    {{ resp }}
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { UploadInstance } from 'element-plus'
import axios from 'axios'

const uploadRef = ref<UploadInstance>()

const resp = ref({})

const submitUpload = () => {
  uploadRef.value!.submit()
}

function mockClick() {
  axios.get('/data/userList').then(r => resp.value = r.data)
}
</script>
